﻿using System;


namespace BizElements.BusinessLayer
{
    /// <summary>
    /// Defines sort expression for <see cref="ISearchEngine"/>.
    /// </summary>
    [Serializable]
    public class SearchEngineSortExpression
    {
        #region Constructors.

        /// <summary>
        /// Initializes a new instance of <b>SearchEngineSortExpression</b> class.
        /// </summary>
        /// <param name="field">Field by whitch the the results are ordered.</param>
        public SearchEngineSortExpression(string field)
        {
            this.Field = field;
        }

        /// <summary>
        /// Initializes a new instance of <b>SearchEngineSortExpression</b> class.
        /// </summary>
        /// <param name="field">Field by whitch the the results are ordered.</param>
        /// <param name="ascending">Specifies whether the values in the specified fields should be sorted in 
        /// ascending order, from lowest value to highest value.</param>
        public SearchEngineSortExpression(string field, bool ascending)
        {
            this.Field = field;
            this.Ascending = ascending;
        }

        #endregion

        #region Properties.

        string field;

        /// <summary>
        /// Gets or sets the display field by whitch the the results are ordered.
        /// </summary>
        /// <value>Name of the display field by whitch the the results are ordered. Default is <b>null</b>.</value>
        /// <exception cref="ArgumentException">Generated if <b>null</b> or <see cref="String.Empty"/> are provided.</exception>
        public string Field
        {
            get { return this.field; }
            set
            {
                if (string.IsNullOrEmpty(value)) throw new ArgumentException("Null or empty string are not allowed");
                this.field = value;
            }
        }

        bool ascending = true;

        /// <summary>
        /// Gets or sets whether the values in the specified fields should be sorted in ascending order, from lowest value to highest value.
        /// </summary>
        /// <value><b>true</b> if ascending order is used; <b>false</b> if descending order is used. Default is <b>true</b>.</value>
        public bool Ascending
        {
            get { return this.ascending; }
            set { this.ascending = value; }
        }

        #endregion
    }
}